package com.example.springdataneo4jdemo.service;

import com.example.springdataneo4jdemo.domain.Person;
import com.example.springdataneo4jdemo.repo.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonService {

    private final PersonRepository personRepository;

    public PersonService(PersonRepository personRepository) {
        this.personRepository = personRepository;
    }

    // 保存 Person
    public Person savePerson(Person person) {
        return personRepository.save(person);
    }

    // 查询所有 Person
    public List<Person> findAllPersons() {
        return personRepository.findAll();
    }

    // 按名字查询 Person
    public List<Person> findByName(String name) {
        return personRepository.findByName(name);
    }

    // 删除 Person
    public void deletePerson(Long id) {
        personRepository.deleteById(id);
    }
}
